package com.bysj.lms.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bysj.lms.pojo.entity.Role;

import com.bysj.lms.mapper.RoleMapper;
import com.bysj.lms.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<Role> getByUsername(String username) {
        List<Role> roles = roleMapper.getByUsername(username);
        return roles;
    }

    @Override
    public PageInfo findByPage(String name, int page, int count) {
        PageHelper.startPage(page,count);
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(name) && StringUtils.isNotEmpty(name),"name",name);
        List<Role> roles = roleMapper.selectList(queryWrapper);
        return new PageInfo(roles);
    }

//    @Autowired
//    RoleMapper roleMapper;
//
//    @Override
//    public List<Role> getRoleById(List<RoleUser> roleUsers) {
//        List<Role> roles = new ArrayList<>();
//        for(RoleUser roleUser : roleUsers){
//            roles.add(getById(roleUser.getRoleId()));
//        }
//        return roles;
//    }
}
